<template>
	<view class="app">
		<view class="price-box">
			<text class="price">{{money}}元</text>
			
			<view class="tui-countdown only_time">
				<text>支付剩余时间</text>
				<tui-countdown class="time" :time="timeList[0]" borderColor="#F2F2F2" backgroundColor="#F2F2F2" colonColor="#F2F2F2" @end="endOfTime"></tui-countdown>
			</view>
			
		</view>

		<view class="pay-type-list">
			<view class="Pay"  @click="changePayType(1)">
				<view class="tit">支付方式</view>
				<view class="typePay">
					<text class="icon yticon icon-weixinzhifu"></text>
					<view class="con">
						<text class="tit">微信支付</text>
					</view>
					<image src="../../static/img/me/checkstand_checked.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="button_bot">
			<text class="mix-btn" @click="confirm">微信支付:{{money}}元</text>
		</view>
	</view>
</template>

<script>

	export default {
		data() {
			return {
				payType: 1,
				orderInfo: {},
				monent:"",
				timeList: [1800,60],
				options:"",
				providerList: [],
				orderId:"",
				money:"",
			};
		},
		computed: {
		
		},
		onLoad(options) {
			this.orderId = options.orderId
			this.money = options.money
			uni.getProvider({
				service: "payment",
				success: (res) => {
					console.log(res);					
					
				},
				fail: (e) => {
					console.log("获取支付通道失败：", e);
				}
			});
		},

		methods: {
			// 支付剩余时间
			endOfTime: function() {
				this.tui.toast("倒计时结束，事件执行")
			},
			
			// 选择支付方式
			changePayType(type) {
				this.payType = type;
			},
			
			// 确认支付
			async confirm() {
				let orderInfo = await this.getOrderInfo();
				
				console.log(orderInfo)
				
				uni.requestPayment({
					provider: 'wxpay',
					orderInfo: orderInfo.data, //订单数据
					success: function(res) {
						console.log('success:' + JSON.stringify(res));
						
						uni.navigateTo({
							url: `/pages/money/paySuccess?orderId=${this.orderId}`
						})
						
					},
					fail: function (err) {
						console.log(err);
						return
					}
				});
			},
			
			// 获取支付的数据
			getOrderInfo(){
				return new Promise((resolve)=>{
					
					this.tui.request("/payWx/appOrder", 'POST',
						{
							"orderId": this.orderId
						},
						false, false, false, )
					.then(res => {
						resolve(res);
					})
					
				})
			},
		}
	}
</script>

<style lang='scss'>
	page{
		height: 100%;
	}
	.app {
		width: 100%;
		height: 100%;
		position: relative;
	}
	.tui-countdown-text {
		font-size: 30rpx;
		line-height: 30rpx;
		color: #555;
	}
	.price-box {
		background-color: #fff;
		height: 265upx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		font-size: 28upx;
		color: #909399;

		.price{
			font-size: 50upx;
			color: #D14798;
			margin-top: 12upx;
			font-weight: 700;
			
			&:before{
				content: '￥';
				font-size: 30upx;
			}
		}
		
		.only_time{
			display: flex;
			align-items: center;
			padding-top: 10px;
			
			
			.time{
				color: #666666;
				padding-left: 10px;
				display: flex;
				align-items: center;
				
			}
		}
		
		
	}

	.pay-type-list {
		margin-top: 20upx;
		background-color: #fff;
		padding-left: 30upx;
		padding-right: 30upx;
		border-top: 10px solid #eeeeee;
		
		.Pay{
			font-size: 14px;
			color: #333333;
			
			
			.tit{
				font-size: 14px;
				color: #333333;
				padding-top: 9px;
				margin-bottom: 16upx;
			}
			
		}
		.typePay{
			display: flex;
			align-items: center;			
			
			.icon-weixinzhifu {
				width: 50upx;
				font-size: 15px;
				color: #36cb59;
			}
			
			.con{
				flex: 1;
				display: flex;
				flex-direction: column;
				font-size: $font-sm;
				color: $font-color-light;
			}
			
			image{
				width: 10px;
				height: 10px;
			}
		}
	}
	.button_bot{
		width: 100%;
		position: absolute;
		bottom: 0;
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow:0px 1px 10px 0px rgba(0, 0, 0, 0.1);
		padding-top: 10px;
		padding-bottom: 10px;
		
		.mix-btn {
			display: block;
			text-align: center;
			line-height: 80upx;
			width: 630upx;
			
			font-size: $font-lg;
			color: #fff;
			background-color: #D14798;
			border-radius: 60upx;
			
			
		}
		
	}
	

</style>
